#include "face_beauty_module.h"


namespace facebeauty
{

FaceBeautyModule::FaceBeautyModule() 
{
    feature_ = 0;
    setuped_ = false;
}

FaceBeautyModule::~FaceBeautyModule()
{

}

int FaceBeautyModule::InitModule(int feature, std::size_t width, std::size_t height, FACE_BEAUTY_COLOR_SPACE color)
{
    if(setuped_) {
        return FACE_BEAUTY_ERROR_FAILED;
    }

    feature_ = (feature & 0x00001111);

    if(feature_ & FACE_BEAUTY_FEATURE_WHITENING) {
        whitening_module_.reset(new CBeautyCore());

        if(!whitening_module_->InitializeBeautyCore(width, height)) {
            return FACE_BEAUTY_ERROR_FAILED;
        }
    }

    if(feature_ & FACE_BEAUTY_FEATURE_BUFFING) {
    }

    if(feature_ & FACE_BEAUTY_FEATURE_BIGEYE) {
    }

    if(feature_ & FACE_BEAUTY_FEATURE_THINFACE) {
    }

    setuped_ = true;

    return FACE_BEAUTY_ERROR_SUCCESS;
}

void FaceBeautyModule::Reset()
{
    return;
}

int FaceBeautyModule::SetFeatureQuality(int feature, int quality)
{
    if(!setuped_) {
        return FACE_BEAUTY_ERROR_FAILED;
    }

    if(!((feature & 0x00001111) & feature_)) {
        return FACE_BEAUTY_ERROR_INVALID_ARG;
    }

    if(feature & FACE_BEAUTY_FEATURE_WHITENING) {
        whitening_module_->SetWhiteningParam(quality);
    }

    return FACE_BEAUTY_ERROR_SUCCESS;
}

int FaceBeautyModule::ProccessFrame(FaceBeautyFrame* in_frame, FaceBeautyFrame* out_frame) 
{
    if(feature_ & FACE_BEAUTY_FEATURE_WHITENING) {
        whitening_module_->ProcessFrame(in_frame->data_[0], in_frame->data_[1], in_frame->data_[2],
                                        in_frame->stride_[0], in_frame->stride_[1], in_frame->stride_[2]);
    }

    return FACE_BEAUTY_ERROR_SUCCESS;
}

int CreateFaceBeautyModule(std::shared_ptr<FaceBeautyInterface> &filter)
{
    filter.reset(new FaceBeautyModule());

    return FACE_BEAUTY_ERROR_SUCCESS;
}

}
